package com.zzyl.controller.customer;

import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ReservationDto;
import com.zzyl.dto.ReservationQueryDto;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController {
    @Autowired
    private ReservationService reservationService;

    @ApiOperation("查询取消预约数量")
    @GetMapping("/cancelled-count")
    public ResponseResult getNum(){
        Integer num = reservationService.getNum();
        return ResponseResult.success(num);

    }

    @ApiOperation("查询每个时间段剩余预约次数")
    @GetMapping("/countByTime")
    public ResponseResult getCount(Long time){
        List<TimeCountVo> timeCountVo = reservationService.getCount(time);
        return ResponseResult.success(timeCountVo);
    }

    @ApiOperation("新增预约")
    @PostMapping
    public ResponseResult<Void> addReservation(@RequestBody ReservationDto dto){
        log.info("新增预约：{}",dto);
        reservationService.addReservation(dto);
        return ResponseResult.success();
    }

    @ApiOperation("分页查询预约")
    @GetMapping("/page")
    public ResponseResult<PageBean<ReservationVo>> findByPage(ReservationQueryDto dto){
        log.info("分页查询预约：{}",dto);
        PageBean<ReservationVo>reservationVoList =reservationService.findByPage(dto);
        return ResponseResult.success(reservationVoList);
    }

    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public ResponseResult<Void> cancelledReservation(@PathVariable Long id){
        log.info("取消预约：{}",id);
        reservationService.cancelReservation(id);
        return ResponseResult.success();
    }
}
